events.listen('recipes', event => {

    let smelterRecipes = [
        {
            output: '6x refinedstorage:quartz_enriched_iron',
            input: ['#forge:ingots/steel', 'create:polished_rose_quartz', '12x #refinedstorage:silicon'],
            energy: 20000
        },
        {
            output: '4x emendatusenigmatica:steel_ingot',
            input: ['4x #forge:ingots/invar', '#forge:dusts/coal_coke'],
            energy: 10000
        },
        {
            output: 'refinedstorage:raw_advanced_processor',
            input: ['6x immersiveengineering:wire_steel', '2x emendatusenigmatica:enderium_nugget', 'refinedstorage:processor_binding'],
            energy: 20000
        },
        {
            output: 'refinedstorage:raw_basic_processor',
            input: ['6x immersiveengineering:wire_aluminum', '2x emendatusenigmatica:invar_nugget', 'refinedstorage:processor_binding'],
            energy: 20000
        },
        {
            output: 'refinedstorage:raw_improved_processor',
            input: ['6x immersiveengineering:wire_electrum', '2x emendatusenigmatica:lumium_nugget', 'refinedstorage:processor_binding'],
            energy: 20000
        },
        {
            output: '3x thermal:rubber',
            input: ['2x #forge:dusts/sulfur', 'pneumaticcraft:plastic'],
            energy: 20000
        },
        {
            output: 'extrastorage:raw_neural_processor',
            input: ['pneumaticcraft:printed_circuit_board', '2x pneumaticcraft:network_data_storage', '2x pneumaticcraft:network_io_port'],
            energy: 20000
        },
        {
            output: '3x emendatusenigmatica:signalum_ingot',
            input: ['2x tconstruct:tinkers_bronze_ingot', '6x minecraft:redstone', '3x emendatusenigmatica:silver_ingot'],
            energy: 20000
        },
        {
            output: '6x kubejs:coarse_crystal_ingot',
            input: ['2x kubejs:polluted_dirt', '3x #quark:crystal'],
            energy: 20000
        },
        {
            output: '4x create:andesite_alloy',
            input: ['minecraft:iron_ingot', '4x kubejs:polluted_dust'],
            energy: 20000
        },
        {
            output: '3x emendatusenigmatica:enderium_ingot',
            input: ['2x minecraft:ender_pearl', '5x #forge:ingots/lead', 'emendatusenigmatica:iridium_ingot'],
            energy: 20000
        },
        {
            output: '2x kubejs:post_radionin_2',
            input: ['3x kubejs:post_radionin_1', '5x #forge:dusts/sulfur', 'pneumaticcraft:bandage'],
            energy: 200000
        },
        {
            output: '8x refinedstorage:quartz_enriched_iron',
            input: ['create:polished_rose_quartz', 'botania:terrasteel_ingot', 'projectred-core:infused_silicon'],
            energy: 20000
        },
        {
            output: '4x emendatusenigmatica:steel_ingot',
            input: ['4x #forge:ingots/invar', 'forbidden_arcanus:corrupti_dust'],
            energy: 10000
        },
        {
            output: 'thermal_extra:vukaium_ingot',
            input: ['emendatusenigmatica:aluminum_ingot', '6x betternether:bone_mushroom'],
            energy: 10000
        },
        {
            output: 'thermal_extra:dragon_bronze_ingot',
            input: ['emendatusenigmatica:bronze_ingot', '6x betternether:agave'],
            energy: 10000
        },
        {
            output: '2x refinedstorage:raw_advanced_processor',
            input: ['2x immersiveengineering:wire_steel', '2x astralsorcery:stardust', 'refinedstorage:processor_binding'],
            energy: 20000
        },
        {
            output: '2x refinedstorage:raw_basic_processor',
            input: ['2x immersiveengineering:wire_aluminum', '2x bloodmagic:defaultcrystal', 'refinedstorage:processor_binding'],
            energy: 20000
        },
        {
            output: '2x refinedstorage:raw_improved_processor',
            input: ['2x immersiveengineering:wire_electrum', '2x minecraft:dragon_breath', 'refinedstorage:processor_binding'],
            energy: 20000
        },
        {
            output: 'extrastorage:raw_neural_processor',
            input: ['refinedstorage:raw_advanced_processor', 'kubejs:item_24', 'bloodmagic:weakbloodshard'],
            energy: 20000
        },
        {
            output: 'create:chromatic_compound',
            input: ['3x betternether:cincinnasite', 'bloodmagic:corrupted_dust', 'forbidden_arcanus:xpetrified_orb'],
            energy: 20000
        },
        {
            output: 'elementalcraft:swift_alloy_ingot',
            input: ['elementalcraft:drenched_iron_ingot', 'elementalcraft:aircrystal', 'projectred-core:red_ingot'],
            energy: 20000
        },
        {
            output: 'forbidden_arcanus:corrupted_pixie_utrem_jar',
            input: ['botania:light_relay', 'astralsorcery:glass_lens', 'forbidden_arcanus:corrupted_pixie'],
            energy: 20000
        },
        {
            output: 'forbidden_arcanus:pixie_utrem_jar',
            input: ['botania:light_relay', 'astralsorcery:glass_lens', 'forbidden_arcanus:pixie'],
            energy: 20000
        },
        {
            output: '2x thermal_extra:nebulium_ingot',
            input: ['3x bloodmagic:corrupted_dust', '2x bloodmagic:weakbloodshard'],
            energy: 20000
        }
    ];


    let color_list = [
        '6x quark:indigo_crystal', //青金石
        '6x quark:blue_crystal',  //钻石
        '6x quark:green_crystal', //绿宝石
        '6x quark:yellow_crystal', //萤石
        '6x quark:orange_crystal', //铜
        '6x quark:red_crystal', //红石
        '6x quark:black_crystal', //煤炭
        '6x quark:white_crystal', //铁
        '6x quark:violet_crystal', //龙
    ];

    let ore_list = [
        '6x minecraft:lapis_block',
        '6x minecraft:diamond_block',
        '6x minecraft:emerald_block',
        '6x minecraft:glowstone',
        '6x emendatusenigmatica:copper_block',
        '6x minecraft:redstone_block',
        '6x minecraft:coal_block',
        '6x minecraft:iron_block',
        '6x draconicevolution:draconium_block'
    ]

    let storage_list = [
        '6x emendatusenigmatica:aluminum_block',
        '6x minecraft:gold_block',
        '6x emendatusenigmatica:zinc_block',
        '6x emendatusenigmatica:nickel_block',
        '6x emendatusenigmatica:tin_block',
        '6x emendatusenigmatica:silver_block',
        '6x emendatusenigmatica:lead_block'
    ]

    let ore_list_2 = [
        '6x emendatusenigmatica:aluminum_chunk',
        '6x emendatusenigmatica:gold_chunk',
        '6x emendatusenigmatica:zinc_chunk',
        '6x emendatusenigmatica:nickel_chunk',
        '6x emendatusenigmatica:tin_chunk',
        '6x emendatusenigmatica:silver_chunk',
        '6x emendatusenigmatica:lead_chunk'
    ]

    smelterRecipes.forEach(i => {
        if (i.input.length == 2) {
            event.recipes.custommachinery.custom_machine("custommachinery:highheat_furnace", 40)
                .requireItem(i.input[0])
                .requireItem(i.input[1])
                .requireEnergy(i.energy)
                .produceItem(i.output)
        } else if (i.input.length == 3) {
            event.recipes.custommachinery.custom_machine("custommachinery:highheat_furnace", 40)
                .requireItem(i.input[0])
                .requireItem(i.input[1])
                .requireItem(i.input[2])
                .requireEnergy(i.energy)
                .produceItem(i.output)
        }
    })

    for (var i = 0; i < ore_list.length; i++) {
        event.recipes.custommachinery.custom_machine("custommachinery:highheat_furnace", 40)
            .requireEnergy(20000)
            .requireFluid(Fluid.of('manaliquidizer:mana_fluid', 5))
            .requireItem(color_list[i])
            .produceItem(ore_list[i])
    }


    for (var i = 0; i < ore_list_2.length; i++) {
        event.recipes.custommachinery.custom_machine("custommachinery:highheat_furnace", 40)
            .requireEnergy(20000)
            .requireFluid(Fluid.of('manaliquidizer:mana_fluid', 5))
            .requireItem(ore_list_2[i])
            .produceItem(storage_list[i])
    }


    event.recipes.custommachinery.custom_machine("custommachinery:highheat_furnace", 200)
        .requireItem('astralsorcery:rock_crystal')
        .requireFluid(Fluid.of('astralsorcery:liquid_starlight', 1000))
        .requireItem('minecraft:glowstone_dust')
        .requireItem('kubejs:paper_foredawn')
        .produceItem('astralsorcery:perk_gem_sky')


    event.recipes.custommachinery.custom_machine("custommachinery:highheat_furnace", 200)
        .requireItem('astralsorcery:rock_crystal')
        .requireFluid(Fluid.of('astralsorcery:liquid_starlight', 1000))
        .requireItem('minecraft:glowstone_dust')
        .requireItem('kubejs:paper_daytime')
        .produceItem('astralsorcery:perk_gem_day')

    event.recipes.custommachinery.custom_machine("custommachinery:highheat_furnace", 200)
        .requireItem('astralsorcery:rock_crystal')
        .requireFluid(Fluid.of('astralsorcery:liquid_starlight', 1000))
        .requireItem('minecraft:glowstone_dust')
        .requireItem('kubejs:paper_night')
        .produceItem('astralsorcery:perk_gem_night')


    const star_map = [
        "evorsio",
        "aevitas",
        "vicio",
        "fornax",
        "octans",
        "bootes",
        "mineralis",
        "horologium"

    ]

    for (let i = 0; i < star_map.length; i++) {
        event.recipes.custommachinery.custom_machine("custommachinery:highheat_furnace", 20)
            .requireItem(`kubejs:paper_a_${i}`, "input1").chance(0)
            .requireItem('astralsorcery:stardust')
            .requireItem('astralsorcery:rock_crystal')
            .requireItem('kubejs:item_25')
            .produceItem(
                {
                    "type": "forge:nbt",
                    "item": "astralsorcery:attuned_celestial_crystal",
                    "count": 1,
                    "nbt": `{astralsorcery:{crystalProperties:{attributes:[{property:\"astralsorcery:size\",pLevel:10,discovered:1b},{property:\"astralsorcery:shape\",pLevel:10,discovered:1b},{property:\"astralsorcery:ritual.range\",pLevel:10,discovered:1b},{property:\"astralsorcery:collector.rate\",pLevel:10,discovered:1b},{property:\"astralsorcery:constellation.${star_map[i]}\",pLevel:10,discovered:1b},{property:\"astralsorcery:ritual.effect\",pLevel:10,discovered:1b},{property:\"astralsorcery:purity\",pLevel:10,discovered:1b}]},constellationName:\"astralsorcery:${star_map[i]}\"}}`
                }
            )
            .requireFunctionOnEnd(ctx => {
                const star_map = [
                    "evorsio",
                    "aevitas",
                    "vicio",
                    "fornax",
                    "octans",
                    "bootes",
                    "mineralis",
                    "horologium"
                ]
                const item_list = [
                    "paper_a_0",
                    "paper_a_1",
                    "paper_a_2",
                    "paper_a_3",
                    "paper_a_4",
                    "paper_a_5",
                    "paper_a_6",
                    "paper_a_7",
                ]
                var item = ctx.machine.getItemStored("input1").getItem();
                console.log(item)
                for (let i = 0; i < item_list.length; i++) {
                    if (item == item_list[i]) {
                        ctx.machine.addItemToSlot(
                            "output1",
                            {
                                "type": "forge:nbt",
                                "item": "astralsorcery:attuned_celestial_crystal",
                                "count": 1,
                                "nbt": `{astralsorcery:{crystalProperties:{attributes:[{property:\"astralsorcery:size\",pLevel:10,discovered:1b},{property:\"astralsorcery:shape\",pLevel:10,discovered:1b},{property:\"astralsorcery:ritual.range\",pLevel:10,discovered:1b},{property:\"astralsorcery:collector.rate\",pLevel:10,discovered:1b},{property:\"astralsorcery:constellation.${star_map[i]}\",pLevel:10,discovered:1b},{property:\"astralsorcery:ritual.effect\",pLevel:10,discovered:1b},{property:\"astralsorcery:purity\",pLevel:10,discovered:1b}]},constellationName:\"astralsorcery:${star_map[i]}\"}}`
                            },
                            false);
                        break;
                    }
                }
                return Result.success()
            })
    }
    


});